package io.renren.modules.job.task;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.util.Random;

/**
 * @Description
 * @Author haijun.zhang@luckincoffee.com
 * @Date 2018-08-09 13:26
 **/
@Component
public class JobTest {

    /**
     * 日志
     */
    private static final Logger LOGGER = LoggerFactory.getLogger(JobTest.class);
    
    public static Random random =new Random();

    @Async
    public void doTaskOne() throws Exception {
        LOGGER.error("开始做任务一");
        long start = System.currentTimeMillis();
        Thread.sleep(random.nextInt(10000));
        long end = System.currentTimeMillis();
        LOGGER.error("完成任务一，耗时：" + (end - start) + "毫秒");
    }

    @Async
    public void doTaskTwo() throws Exception {
        LOGGER.error("开始做任务二");
        long start = System.currentTimeMillis();
        Thread.sleep(random.nextInt(10000));
        long end = System.currentTimeMillis();
        LOGGER.error("完成任务二，耗时：" + (end - start) + "毫秒");
    }

    @Async
    public void doTaskThree() throws Exception {
        LOGGER.error("开始做任务三");
        long start = System.currentTimeMillis();
        Thread.sleep(random.nextInt(10000));
        long end = System.currentTimeMillis();
        LOGGER.error("完成任务三，耗时：" + (end - start) + "毫秒");
    }

}